package com.cy.sc.config;

import com.cy.sc.filter.MyZuulFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * <br>@class: BeanConfig
 * <br>@description: boot配置 bean 将自定义组件 加入spring中
 * <br>@author: cy
 * <br>@date: 2020-04-03 21:56:55
 * <br>@version: 1.0
 * <br>
 * <br>@since: (版本) 作者 时间 注释
 */
@Configuration
public class BeanConfig {
    @Bean
    public MyZuulFilter getMyZuulFilter(){
        return new MyZuulFilter();
    }

    @Bean
    public CorsFilter corsFilter() {
        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");//允许跨域源
        config.addAllowedHeader("*");//允许的header参数
        config.addAllowedMethod("*");//允许的请求方式
        config.setMaxAge(18000L);
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }


}
